//
//  SettingViewController.m
//  FoodFamily
//
//  Created by Bang-guo on 15-6-19.
//  Copyright (c) 2015年 guoBang. All rights reserved.
//

#import "SettingViewController.h"

@interface SettingViewController ()

@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    设置状态栏的背景颜色
    UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, -20, WIDTH, 20)];
    statusBarView.backgroundColor=[UIColor blackColor];
    [self.navigationController.navigationBar addSubview:statusBarView];
    self.view.backgroundColor = [UIColor lightGrayColor];
    self.navigationController.navigationBar.translucent = NO;
    //设置navigationBar的背景颜色和标题颜色
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"690EFC73-E213-4C10-9FF7-CCE713AC7BC1.png"] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:19.0]}];
    
    [statusBarView release];
    self.navigationItem.title = @"设置";
    self.mytableview = [[UITableView alloc]initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStylePlain];
    self.mytableview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.mytableview];
    self.mytableview.delegate = self;
    self.mytableview.dataSource = self;

    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 100)];
    view1.backgroundColor = [UIColor lightGrayColor];
    view1.alpha = 0.3;
    UILabel *lable1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, WIDTH, 30)];
    lable1.text = @"团队:GYB";
    lable1.textAlignment = NSTextAlignmentCenter;
    [view1 addSubview:lable1];
    UILabel *lable2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, WIDTH, 30)];
    lable2.text = @"2014 ~ 2015";
    lable2.textAlignment = NSTextAlignmentCenter;
    [view1 addSubview:lable2];
    UILabel *lable3 = [[UILabel alloc] initWithFrame:CGRectMake(0, 100 - 30, WIDTH, 30)];
    lable3.text = @"All Rights Reserved.";
    lable3.textAlignment = NSTextAlignmentCenter;
    [view1 addSubview:lable3];
    self.mytableview.tableFooterView = view1;
    
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT / 4)];
    imageV.image = [UIImage imageNamed:@"settingHeader.png"];
    self.mytableview.tableHeaderView = imageV;

}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{


    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return 1;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return @" ";
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"mycell";
    SettingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell ==nil) {
        cell = [[[SettingTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]autorelease];
    }
    if (indexPath.section ==0) {
        
//        cell.textLabel.text = @"我的收藏";
        [cell writeCell:@"我的收藏"];
    
    }else if (indexPath.section==1)
    {
//        cell.textLabel.text = @"清除缓存";
        [cell writeCell:@"清除缓存"];
        
    }else if (indexPath.section==2)
    {
//        cell.textLabel.text = @"关于我们";
        [cell writeCell:@"联系我们"];
//        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    
    return cell;
}
//点击触发方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    //[tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row ==0&&indexPath.section==0) {
        CollectViewController *collect = [[CollectViewController alloc]init];
        [self.navigationController pushViewController:collect animated:YES];
    }else if (indexPath.row ==0&&indexPath.section ==1)
    {
        
        NSUInteger size = [[SDImageCache sharedImageCache]getSize];
        CGFloat mb = size/1024.0/1024.0;
        self.imageSize = [NSString stringWithFormat:@"缓存数据:%.2fMB",mb];
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:self.imageSize message:@"是否清除缓存数据" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alert show];
        [self.mytableview reloadData];
      
    }else if (indexPath.row == 0&&indexPath.section==2)
    {
//        PeopleViewController *people = [[PeopleViewController alloc]init];
//        [self.navigationController pushViewController:people animated:YES];
        
        UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:@"联系我们" message:@"\nEmail:bang_guo_hope365@163.com \n\n 开发者:郭榜  杨涛  白明政" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alertV show];

    }


}
// 清除缓存协议方法咕~~(╯﹏╰)b
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [[SDImageCache sharedImageCache]cleanDisk];
    ////////////////
    if (buttonIndex ==1) {
        
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *cachpath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)objectAtIndex:0];
        NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachpath];
        
        for (NSString *p in files) {
            NSError *error;
            NSString *path = [cachpath stringByAppendingPathComponent:p];
            if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
                [[NSFileManager defaultManager] removeItemAtPath:path error:&error];
            }
        }
        [self performSelectorOnMainThread:@selector(clearCacheSuccess) withObject:nil waitUntilDone:YES];    });
    NSLog(@"大水杯");}
}
////////////
-(void)clearCacheSuccess
{
    NSLog(@"清理成功");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
